/////////////////////////////////////////////////////////////////////////////
// Name:        prefers.cpp
// Purpose:     
// Author:      Brant Young
// Modified by: 
// Created:     Thu Jun 21 23:17:25 2007
// RCS-ID:      
// Copyright:   (C) Victsoft 2007
// Licence:     GPL 2.0
/////////////////////////////////////////////////////////////////////////////


#include <wx/wx.h>
#include <wx/imaglist.h>

#include "prefersdialog.h"
#include "generalpanel.h"
#include "networkpanel.h"
#include "updatepanel.h"
#include "thememgr.h"
#include "cfgmgr.h"


/*!
 * PrefersDialog constructors
 */

PrefersDialog::PrefersDialog(wxWindow* p_parent)
{	
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create(p_parent, ID_PREFERS_DLG, _("Preferences"), wxDefaultPosition,\
    		 wxDefaultSize, wxCAPTION| \
    		wxSYSTEM_MENU|wxCLOSE_BOX);
    CreateControls();
    Fit();
    CentreOnScreen();
}


/*!
 * Control creation for PrefersDialog
 */

void PrefersDialog::CreateControls()
{    
////@begin PrefersDialog content construction

    p_root_sizer = new wxBoxSizer(wxVERTICAL);
    this->SetSizer(p_root_sizer);

    p_root_notebook = new wxToolbook( this, ID_ROOT_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxBK_DEFAULT );
    wxImageList* p_root_notebookImageList = new wxImageList(32, 32, true, 1);
    {
        ThemeManager& theme_mgr = ThemeManager::get();
        
        wxBitmap& bmp0 = theme_mgr.get_bitmap(_T("general-32.png"));
        p_root_notebookImageList->Add(bmp0);
        
        wxBitmap& bmp1 = theme_mgr.get_bitmap(_T("network-32.png"));
        p_root_notebookImageList->Add(bmp1);
        
        wxBitmap& bmp2 = theme_mgr.get_bitmap(_T("update-32.png"));
        p_root_notebookImageList->Add(bmp2);
    }
    p_root_notebook->AssignImageList(p_root_notebookImageList);
    
    p_general_panel = new GeneralPanel(p_root_notebook);

    p_root_notebook->AddPage(p_general_panel, _("General"), false, 0);

    p_network_panel = new NetworkPanel(p_root_notebook);

    p_root_notebook->AddPage(p_network_panel, _("Network"), false, 1);

    p_update_panel = new UpdatePanel(p_root_notebook);

    p_root_notebook->AddPage(p_update_panel, _("Update"), false, 2);

    p_root_sizer->Add(p_root_notebook, 1, wxGROW, 0);
    p_root_notebook->Fit();
    
    p_std_button_sizer = new wxStdDialogButtonSizer;

    p_root_sizer->Add(p_std_button_sizer, 0, wxGROW|wxALL, 5);
    p_ok_btn = new wxButton( this, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    p_std_button_sizer->AddButton(p_ok_btn);

    p_cancel_btn = new wxButton( this, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    p_std_button_sizer->AddButton(p_cancel_btn);

    p_help_btn = new wxButton( this, wxID_HELP, _("&Help"), wxDefaultPosition, wxDefaultSize, 0 );
    p_std_button_sizer->AddButton(p_help_btn);

    p_std_button_sizer->Realize();

////@end PrefersDialog content construction
    
    InitEvents();
}


void PrefersDialog::InitEvents() {
	this->Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, 
			(wxObjectEventFunction)&PrefersDialog::OnOK);
}

void PrefersDialog::OnOK(wxCommandEvent& event) {
	p_general_panel->set_cfg();
	p_network_panel->set_cfg();
	p_update_panel->set_cfg();
	
	ConfigManager::get().Flush();
	event.Skip();
}
